import type { App } from 'vue'

// 将所有的组件注册到全局（实际引入的是 index.ts）
import Button from '@/components/Button'
import Message, { createMessage } from '@/components/Message'
import Form, { FormItem } from '@/components/Form'
import Input from '@/components/Input'
import Select from '@/components/Select'
import Collapse, { CollapseItem } from '@/components/Collapse'
import Icon from '@/components/Icon'
import Switch from '@/components/Switch'
import Tooltip from '@/components/Tooltip'
import Dropdown from '@/components/Dropdown'

// 引入图标
import { library } from '@fortawesome/fontawesome-svg-core'
import { fas } from '@fortawesome/free-solid-svg-icons'
library.add(fas)

import './styles/index.scss'

const components = [
    Button,
    Message,
    Form, FormItem,
    Input,
    Select,
    Collapse, CollapseItem,
    Icon,
    Switch,
    Tooltip,
    Dropdown
]

// 创建一个 install函数，作为一个全局的插件，去循环注册所有组件
const install = (app: App) => {
    components.forEach(component => {
        if (component.name) {
            app.component(component.name, component)
        } else {
            console.warn(`Component ${component} has no name and will not be registered.`);
        }
    })
}

export {
    install,
    Button,
    Message,
    Form, FormItem,
    Input,
    Select,
    Collapse, CollapseItem,
    Icon,
    Switch,
    Tooltip,
    Dropdown, createMessage
}

export default {
    install
}